input_str = '  今天天气好  '
print(input_str)
print(input_str.strip())
print(input_str.lstrip())
input_str = 'AAA今天天气好  '
print(input_str.strip('A'))

print('abc'.isalpha())
print('AB和'.isalpha())
print('  123'.isalpha())
print('  好', '  好'.isalpha())
print('123'.isalpha())
print('AB'.isalpha())
print('123 '.isnumeric())
print('123'.isnumeric())
print('123', '123'.isdigit())
print('123.45', '123.45'.isdigit())

# 分割
input_str = '今天 天气 真好 very good     '
input_list = input_str.split(' ')
print(input_list)
print(''.join(input_list))

import re

pattern = re.compile(r'.')
print(re.findall(pattern, 'very good '))
pattern = re.compile(r'[abc ]')
print(re.findall(pattern, 'very abc goodab c '))
pattern = re.compile(r'[a-d]')
print(re.findall(pattern, 'very abc goodab c '))
#
pattern = re.compile(r'[^a-d ]')
print(re.findall(pattern, 'very 123abc goodab c '))

pattern = re.compile(r'[a-d]|[12]')
print(re.findall(pattern, 'very 123abc goodab c '))

pattern = re.compile(r'[a-d]|[\d]')
print(re.findall(pattern, 'very 123abc goodab c '))

# *  zero times or many times

pattern = re.compile(r'\s')
print(re.findall(pattern, '你好 123abc goodab c '))
pattern = re.compile(r'\d')
print(re.findall(pattern, 'very 123abc goodab c '))

pattern = re.compile(r'\d*')
print(re.findall(pattern, 'very 123abc goodab c '))

# +  one time  or more than one time
pattern = re.compile(r'\d+')
print(re.findall(pattern, 'very 123abc goodab12 c '))

# {m,n}  m<=times<=n
pattern = re.compile(r'\d{2,3}')
print(re.findall(pattern, '1very 123abc goodab12 1324214c '))

# {m,n}  m<=times<=n
pattern = re.compile(r'\d')
print(re.match(pattern, '1very  123abc goodab12 1324214c ').group())
print(re.search(pattern, 'very1  123abc goodab12 1324214c ').group())

print(re.subn(re.compile(r'\d'), '数字', 'very1  123abc goodab12 1324214c '))
print(re.subn(re.compile(r'\d'), '', 'very1  123abc goodab12 1324214c '))

print(re.split(re.compile(r'\d+'), 'very1  123abc goodab12 1324214c '))
print(re.split(re.compile(r'\d'), 'very1  123abc goodab12 1123456c '))
print(re.split(re.compile(r'\d'), 'a1234a'))
print(re.split(re.compile(r'\d'), 'a12345a'))

# group name (?P...)
print(re.search(re.compile(r'(?P<dota>\d+)(?P<lol>\D+)'), 'a12345a').group('lol'))
print(re.search(re.compile(r'(?P<dota>\d+)(?P<lol>\D+)'), 'a12345a').group())
